<?php
/**************************************************************************
 * Naanal PHP Framework, Simple, Efficient and Developer Friendly
 * Ver 3.0, Copyright (C) <2010>  <Tamil Amuthan. R>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ************************************************************************/
class ClsLPhpexcel extends ClsNaanalLibrary
{
    private $objPHPExcel=null;
    private $arrData=array();
    public function __construct() {
        parent::__construct();
        $this->objPHPExcel = new PHPExcel();
        $this->currentSheet=$this->objPHPExcel->setActiveSheetIndex(0);
    }
    public function setDataStructure($arrData)
    {
        $this->arrData=$arrData;
    }
    public function setActiveSheetIndex($index)
    {
        $this->currentSheet=$this->objPHPExcel->setActiveSheetIndex($index);
    }
    public function addData($xLower,$yLower,$xUpper,$yUpper,$data)
    {
        $this->arrData[]=array("xLower"=>$xLower+1,"yLower"=>$yLower+1,"xUpper"=>$xUpper+1,"yUpper"=>$yUpper+1,"data"=>$data);
    }
    public function save($path)
    {
        $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'Excel5');
        $objWriter->save($path);
    }
    public function render()
    {
        ob_clean();
        $alhpa="A";
        
        $tmp="";
        foreach($this->arrData as $cell)
        {
            if($cell["xUpper"]>26)
            {
                $alphaNum=$cell["xUpper"] % 26;
                $charUpper="A".chr($alphaNum + 64);
                $charLower=chr($cell["xLower"] + 64);
            }
            else
            {
                $charUpper=chr($cell["xUpper"] + 64);
                $charLower=chr($cell["xLower"] + 64);
            }
            $rowNum=$cell["yUpper"];$tmp=$tmp."{$charUpper}{$rowNum}, ";
            $this->currentSheet->setCellValue("{$charUpper}{$rowNum}", $cell["data"]);
        }
    }
}
?>